package com.wavecoler.professor.dao;

import java.util.List;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.wavecoler.professor.objects.Advice;
import com.wavecoler.professor.objects.AdviceType;
import com.wavecoler.dao.PMF;


public class AdviceDAO {
	
	// Insertar, Modificar y Eliminar
	
	public void saveAdvice(String adviceNum, String adviceText, AdviceType adviceType, String phaseSession, String adviceKind)throws Exception {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Advice advice = new Advice(adviceNum, adviceText, adviceType, phaseSession, adviceKind);
		
		//try {-
            pm.makePersistent(advice); 
		//}	finally {
            pm.close();
        //}
	}
	
	@SuppressWarnings("unchecked")
	public List<Advice> listAdvices() {
		PersistenceManager pm = PMF.get()
				.getPersistenceManager();
		String query = "select from " + Advice.class.getName();
		return (List<Advice>) pm.newQuery(query).execute();
	}
	
/*	public void removeAdvice(Advice advice) {
		PersistenceManager pm = getPersistenceManagerFactory()
				.getPersistenceManager();
		try {
			pm.currentTransaction().begin();

			// We don't have a reference to the selected Product.
			// So we have to look it up first,
			advice = pm.getObjectById(Advice.class, advice.getAdviceId());
			pm.deletePersistent(advice);

			pm.currentTransaction().commit();
		} catch (Exception ex) {
			pm.currentTransaction().rollback();
			throw new RuntimeException(ex);
		} finally {
			pm.close();
		}
	} */
}

